package cbfg.http.util

import okhttp3.MediaType

object Utils {
    internal fun <T> validateServiceInterface(service: Class<T>) {
        require(service.isInterface) { "API declarations must be interfaces." }
        // Prevent API interfaces from extending other interfaces. This not only avoids a bug in
        // Android (http://b.android.com/58753) but it forces composition of API declarations which is
        // the recommended pattern.
        require(service.interfaces.isEmpty()) { "API interfaces must not extend other interfaces." }
    }

    fun getFileMediaType(filePath: String): MediaType? {
        val temp = filePath.split("\\.".toRegex()).toTypedArray()
        return when (temp[temp.size - 1].toLowerCase()) {
            "jpg", "jpeg" -> MediaType.parse("image/jpeg")
            "png" -> MediaType.parse("image/png")
            "bmp" -> MediaType.parse("image/bmp")
            else -> MediaType.parse("application/octet-stream")
        }
    }
}